package easier.camera;

import android.Manifest.permission;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import androidx.activity.result.ActivityResultCallback;
import androidx.appcompat.app.AppCompatActivity;
import easier.app.x.result.Permission;

public class MainActivity extends AppCompatActivity {

    private Button mPreview;
    private Button mPermission;
    private Button mAnalysis;

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main );
        initView();
    }

    private void initView() {

        mPreview = (Button) findViewById( R.id.preview );
        mPreview.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                Permission.registerForPermissionResult( getSupportFragmentManager(), permission.CAMERA,
                    new ActivityResultCallback< Boolean >() {
                        @Override
                        public void onActivityResult( Boolean result ) {

                            if ( result ) {
                                MainActivity2.start( v.getContext() );
                            }
                        }
                    } );
            }
        } );
        mPermission = (Button) findViewById( R.id.permission );
        mPermission.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                Permission.registerForPermissionResult( getSupportFragmentManager(), permission.CAMERA,
                    new ActivityResultCallback< Boolean >() {
                        @Override
                        public void onActivityResult( Boolean result ) {

                            if ( result ) {
                                MainActivity2.startFront( v.getContext() );
                            }
                        }
                    } );
            }
        } );
        mAnalysis = (Button) findViewById( R.id.analysis );
        mAnalysis.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                Permission.registerForPermissionResult( getSupportFragmentManager(), permission.CAMERA,
                    new ActivityResultCallback< Boolean >() {
                        @Override
                        public void onActivityResult( Boolean result ) {

                            if ( result ) {
                                MainActivity4.start( v.getContext() );
                            }
                        }
                    } );
            }
        } );
    }
}